<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="发起人" prop="nickName">
        <el-input
          v-model="queryParams.nickName"
          clearable
          placeholder="请输入发起人名称"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="会议名称" prop="meetingName">
        <el-input
          v-model="queryParams.meetingName"
          placeholder="请输入会议名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="开始时间" prop="daterangeRemindTime">
        <el-date-picker
          v-model="daterangeRemindTime"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始时间"
          end-placeholder="结束时间"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['videotape:recording:export']"
        >导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="recordingList">
      <el-table-column type="index" :index="indexMethod" width="55" label="序号" align="center"/>
      <el-table-column label="发起人" align="center" prop="nickName"/>
      <el-table-column label="性别" align="center" prop="sex">
        <template slot-scope="scope">
          <span> {{ scope.row.sex === '0' ? '男' : scope.row.sex === '1' ? '女' : '未知' }} </span>
        </template>
      </el-table-column>
      <el-table-column label="手机号" align="center" prop="phoneNumber"/>
      <el-table-column label="会议开始时间" align="center" prop="startTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.startTime, '{y}-{m}-{d} {h}:{i}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="会议名称" align="center" prop="meetingName"/>
      <el-table-column label="会议发起时间" align="center" prop="meetingLaunchDate" width="180">
        <template slot-scope="scope">
          <span> {{ parseTime(scope.row.meetingLaunchDate, '{y}-{m}-{d} {h}:{i}') }} </span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-video-camera"
            @click="handleEnter(scope.row)"
            v-hasPermi="['videotape:recording:enter']"
          >进入会议
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <!--进入我的会议-->
    <el-dialog :visible.sync="open"  title="进入会议" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" size="medium" label-width="80px">
        <el-form-item label="密码" prop="password">
          <el-input v-model="form.password" placeholder="请输入密码" clearable show-password
                    :style="{width: '100%'}"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="close">取消</el-button>
        <el-button type="primary" @click="submitForm">确定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {listRecording,recordingEnter} from "@/api/videotape/recording"
import {parseTime} from "@/utils/ruoyi";

export default {
  name: "Recording",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 选择时间氛围
      daterangeRemindTime: [],
      // 视频会议表格数据
      recordingList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        nickName: null,
        meetingName: null,
        startTime: null,
        startDate: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        password: [{
          required: true,
          message: '请输入密码',
          trigger: 'blur'
        }],
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    parseTime,

    indexMethod(index) {
      return index + 1;
    },
    /** 查询视频会议列表 */
    getList() {
      this.loading = true
      if (null != this.daterangeRemindTime && '' != this.daterangeRemindTime) {
        this.queryParams.beginRemindTime = this.daterangeRemindTime[0]
        this.queryParams.endRemindTime = this.daterangeRemindTime[1]
      }
      listRecording(this.queryParams).then(response => {
        this.recordingList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        inviterId: null,
        userId: null,
        meetingName: null,
        startTime: null,
        startDate: null,
        password: null,
        id: null,
        state: null,
        reason: null,
        meetingLaunchDate: null,
        isAttendance: null,
        attendanceTime: null
      }
      this.resetForm("form")
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm")
      this.handleQuery()
    },
    close(){
      this.resetForm("form")
      this.open = false
    },
    handleEnter(row) {
      this.form = {}
      this.form.id = row.id
      this.open = true
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          let fromData = {}
          fromData.id = this.form.id
          fromData.password = this.form.password
          recordingEnter(fromData).then(res => {
            if (res.data === undefined){
              this.$message.error('密码错误')
            }else {
              this.$message.success(`已成功进入${res.data.meetingName}会议`)
              this.$router.push({ path: '/meeting/comeinto' })
              this.open = false
            }
          })
        }
      })
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('videotape/recording/export', {
        ...this.queryParams
      }, `recording_${new Date().getTime()}.xlsx`)
    }
  }
}
</script>
